package com.running.base.run.util;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.Map;

/**
 * Created by Daniel on 12/10/2016.
 */
public class JsonUtils {

    public static String toJson(Object object) {
        if (object == null) {
            return "";
        }
        return JSON.toJSONString(object);
    }

    public static Object parseObject(String object, Class clz) {
        if (object == null) {
            return null;
        }
        return JSON.parseObject(object, clz);
    }

    public static Map<String, String> convertObject2Map(Object object) {
        if (object == null) {
            return null;
        }
        ObjectMapper m = new ObjectMapper();
        Map<String, String> props = m.convertValue(object, Map.class);
        return props;
    }
    
}
